package operation;

import book.Book;
import book.Booklist;

import java.util.Scanner;

public class Borrow implements Canoperation {
    public void work(Booklist booklist) {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入您要借阅的书名");
        String name = sc.nextLine();
        int sum = booklist.getBooksum();
        for (int i = 0; i < sum; i++) {
            Book book = booklist.getbook(i);
            if(name.equals(book.getName())){
                if(!book.getisIsborrow()){
                    System.out.println("借阅成功");
                    book.setIsborrow(true);
                    return;
                }else {
                    System.out.println("抱歉，该图书已被借走");
                    return;
                }
            }
        }
        System.out.println("抱歉，图书馆没有此书");
    }
}
